// Zepto
var $ = require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');

module.exports = $;

// 引入Swiper

var Swiper = require('./components/swiper/swiper.min.js');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min.js');
var swiper = new Swiper('.swiper-container', {
    onInit: function (swiper) { //Swiper2.x的初始化是onFirstInit
        swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
        swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
    },
    onSlideChangeEnd: function (swiper) {
        swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
    },
    pagination: '.swiper-pagination',
    direction: 'vertical',
    slidesPerView: 1,
    paginationClickable: true,
    spaceBetween: 30,
    mousewheelControl: true
})








var IScroll = require('./components/iscroll/iscroll');
$("#mainContainer").hide();
$(".swiper-container").hide();
// jquery/zepto
$("#enter").tap(function () {
    $(".swiper-container").hide();
    $("#mainContainer").show();

    $.ajax({
        type: 'GET',
        url: 'http://localhost:8000/api/skill.php',
        dataType: 'json',
        success: function (data) {
            var html = "";
            for (var i = 0; i < data.length; i++) {
                html += "<li>" + data[i].name + "</li>";
            }
            $("#scroller ul").html(html);
        }
    })


    myScroll = new IScroll('#wrapper', {
        mouseWheel: true
    });
    document.addEventListener('touchmove', function (e) {
        e.preventDefault()
    }, false);
})

$("#footer div").tap(function () {
    var apiTarget = $(this).attr('id');
    var apiUrl = "http://localhost:3000/api" + apiTarget + ".php";

    $.ajax({
        type: 'GET',
        url: apiUrl,
        success: function (data) {
            var html = "";
            for (var i = 0; i < data.length; i++) {
                html += "<li>" + data[i].name + "</li>";
            }
            $("#scroller ul").html(html);
        }
    })

})

var interval = setInterval(function () {
    if (document.readyState === 'complete') {
        clearInterval(interval);
        $("#loading").hide();
        $(".swiper-container").show();
        swiper.updateContainerSize(); // 万分重要
        swiper.updateSlidesSize(); // 万分重要
    } else {
        $("#loading").show();
    }
})